public class 无重复字符的最长子串 {

    public int lengthOfLongestSubstring(String ss) {
        char[] s = ss.toCharArray();
        int n = s.length;
        int[] hash = new int[256];
        int l = 0;
        int ans = 0;
        for (int r = 0; r < n; r++) {
            if (hash[s[r]]++ > 0) {
                while (--hash[s[l++]] != 1);
            }
            ans = Math.max(ans,r - l + 1);
        }
        return ans;
    }
}
